import { _decorator, Component, EventHandler, find, Node } from 'cc';
import GameEventMgr, { GameEvent } from '../../Model/GameEventMgr';
import { UICtrl } from '../../Ctrl/UICtrl';
import TextDialog from '../Dialog/TextDialog';
import { GameOverDialog } from '../Dialog/GameOverDialog';
import SoundCtrl from '../../Ctrl/SoundCtrl';
import { Global } from '../../Util/Global';
const { ccclass, property } = _decorator;

@ccclass('UIOnClickMgr')
export class UIOnClickMgr extends Component {

    onClickSound(event: EventHandler, customEventData: string) {
        let data = Number(customEventData || 0);
        if (data == 0) {
            SoundCtrl.playEffect('mouseclick1');
        }
        else if (data == 1) {
            SoundCtrl.playEffect('mouserelease1');
        }
    }

    onClickHomeBtn() {
        UICtrl.hideDialog(GameOverDialog);
        UICtrl.showDialog(TextDialog).setData({
            rightBtnClick: (dialog) => {
                dialog.close();
                GameEventMgr.Dispatch(GameEvent.OnClickBackHome);
                find('UICanvas/StartGameViewUI').active = true;
            },
            text: '我知道已被忘却，流浪的航程太长太长，但那一时刻要叫我一声啊，当东方再次出现霞光。\n' +
                '......\n' +
                '你确定终止流浪地球计划吗？文明的种子将延续。',
        });
    }

    onClickPause(event: EventHandler, customEventData: string) {
        Global.gameManager.pause = !Global.gameManager.pause;
        let pause = Global.gameManager.pause;
        let pa = event.target.getChildByName('pause');
        pa.active = !pause;
        let pl = event.target.getChildByName('play');
        pl.active = pause;
    }
}


